#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
long get_dir_size(char path[]){
	DIR *d;
	struct dirent *de;
	struct stat buf;
	int exists;
	long byte = 0;
	char tmp[1000];

	d = opendir(path);
	if (d == NULL) {
		perror("prsize");
		exit(1);
	}

	while( NULL!=(de = readdir(d)) ){
		const char * cur = ".";
		const char * parent = "..";
		if( strcmp(de->d_name, cur)==0 || strcmp(de->d_name, parent)==0 ) continue;
		sprintf(tmp, "%s\\%s", path, de->d_name);
		exists = stat(tmp, &buf);
		if (exists < 0) {
			fprintf(stderr, "Couldn't stat %s\n", tmp);
		} else {
			if( buf.st_mode & S_IFDIR ){
				sprintf(tmp, "%s\\", tmp);
				byte += get_dir_size( tmp );
			}else{
				byte += buf.st_size;
			}
		}
	}
	closedir(d);
	return byte;
}
int main(int argc, char** argv){
	long long byte = get_dir_size( argv[1] );
	//Linux gcc, VS2008 %lld
	//VC6 MinGW gcc %I64d
	printf("%I64d\n", byte);
	//printf("%lld\n", byte);
	return 0;
} 
